#ifndef COM_DATA_PROCESS_H
#define COM_DATA_PROCESS_H

#include <QWidget>
#include <QSqlQuery>
#include <QMap>
#include <QSqlQueryModel>
#include "pub_pop_delay.h"
#include <QTcpServer>
#include <QTcpSocket>
#include <QElapsedTimer>

namespace Ui {
class com_data_dump;
}

class com_data_dump : public QWidget
{
    Q_OBJECT

public:
    explicit com_data_dump(QWidget *parent = nullptr);
    ~com_data_dump();

    void closeEvent(QCloseEvent *event);

signals:
    void destroyW( QString );

private slots:

    bool export_text(QMap<QString,QString> *, QSqlQuery * , QString);
    bool import_table(QMap<QString, QString> *, QSqlQuery * , QString);

    void on_pb_close_clicked();

    void on_pb_import_clicked();

    void on_pb_dump_clicked();

    void on_pb_connect_s_clicked();

    void on_pb_connect_d_clicked();

    void on_tb_openfile_clicked();

    void on_pb_get_fields_clicked();

    void on_pb_get_local_d_clicked();

    void on_pb_get_local_s_clicked();

    void on_pb_fresh_online_user_clicked();

    void on_tv_user_list_clicked(const QModelIndex &index);

    void on_tv_user_list_doubleClicked(const QModelIndex &index);

    void on_pb_download_clicked();

    void connect_count_down();

    void on_pb_get_file_list_clicked();

    void handle_connect_timeout();

    void read_file_list();
    void send_file_apply();
    void get_file();

private:
    Ui::com_data_dump *ui;

    Pub_pop_delay * dlg_delay;

    QSqlDatabase db_o_s, db_o_d;   // oracle
    QSqlDatabase db_m_s, db_m_d;   //mysql

    QSqlQuery *qrm_s, *qro_s, *qrot_s, *qrmt_s;
    QSqlQuery *qrm_d, *qro_d, *qrot_d, *qrmt_d;

    QString sq;

    QString downloadPath;   //dump file path

    bool source_connected, dest_connected;

    QSqlQuery *qrm_log, *qro_log;
    QSqlQueryModel *md_log;

    QTcpSocket *current_socket ;
    QFile file;
    QString fileName;
    qint64 fileSize;
    qint64 bytesReceived ;

    QString dest_ip;
    QTimer *tm_connect;
    QTimer *tm_connect_count_down;
    int connect_count;
    QElapsedTimer speedTimer;
    QString remote_file_name, local_file_name;
    qint64 remote_file_size;
    int elapsed_second;

    QByteArray btar_file_list;
    int file_list_size;
    bool is_first_read_file_list;

};

#endif // COM_DATA_PROCESS_H
